from Systems.Solar import *
from Systems.Planets.PlanetTypes import *

import random

SUNMASS = 1.9891*10**30 # 1.9891 *10**30 kg 
SUNVOLUME = 1.4122*10**27 # 1.4122*10**27 km3
SUNDENSITY = 1.408 # 1.408 g/cm3
SOLARMASSES = 2*10**30 # 

MAXAUPERSOLARMASS = 50 # AU

class SolarCoreEnum:
    BLUE = "Blue Star"
    BLUEWHITE = "Blue-White Star"
    WHITE = "White Star"
    YELLOWWHITE = "Yellow-White Star"
    YELLOW = "Yellow Star"
    ORANGE = "Orange Star"
    RED = "Red Star"
    BROWNDWARF = "Brown Dwarf"
    WHITEDWARF = "White Dwarf"
    PULSAR = "Neutron Pulsar Star"
    MAGNETAR = "Neutron Magnetars Star"
    BLACK= " Black Body Mass"

class SolarCore(SolarBody):
    """ Solar Core """
    brightness = 0 # watts for a square meter at 1 AU
    
    brightnessLower = 100
    brightnessUpper = 1000
    
    massLower = .1
    massUpper = 1
    
    diameterLower = .1
    diameterUpper = 1    
        
    def rawWattsForAU(self, au):
        return brightness / (au * au) # inverse square law, I = 1/r^2
    
    def makeRandom(self):
        self.mass = self.getRandomMass()
        self.radius = self.getRandomSize()
        self.brightness = self.getRandomBrightness()
    
    def getRandomMass(self):
        m = (random.random() * (self.massUpper - self.massLower)) + self.massLower
        return (m * SUNMASS)
    
    def getRandomSize(self):
        d = (random.random() * (self.diameterUpper - self.diameterLower)) + self.diameterLower
        return (700000 * d) #converts to radius
    
    def getRandomBrightness(self):
        b = random.randint(self.brightnessLower, self.brightnessUpper)
        return b
    
    def getSolarMasses(self):
        return self.mass / SOLARMASSES
        
    def __str__(self):
       s = "[[Solar Core Type: " + self.type + "\n"
       s = s + "  Class: " + self.letterCode + "\n"
       s = s + "  Mass: "  + str(self.mass) + " (" + str(self.getSolarMasses()) + " solar masses)\n"
       s = s + "  Radius: " + str(self.radius) + " (" + str(self.radius / AU) + " AU)\n"
       s = s + "  Brightness at 1 AU:" + str(self.brightness)
       return s  + " ]]"
        
    
class SolarCoreFactory():
    
    def makeCore(self): abstract
    
    def getSolarBodiesFactory(self): abstract
    
    def makeRandomBody(self, au, solarmass):
        p = int(round((au / (MAXAUPERSOLARMASS * solarmass))) * 100)
    
        if p <= 2:
            return self.makeRandomInnerBody()
        elif p < 11:
            return self.makeRandomMidBody()
        elif p < 60:
            return self.outterRandomBody()
        elif p >= 60:
            return self.beltRandomBody()
        

    def makeRandomInnerBody(self):
        r = random.randint(1,100)
    
        if r <= 15:
            return LightTerrestrial().makePlanet()
        elif r < 35:    
            return BarrenFactory().makePlanet()
        elif r < 65:
            return DenseTerrestrial().makePlanet()
        elif r >= 65:
            return GasGaint().makePlanet()
    
    def makeRandomMidBody(self):
        return MediumTerrestrial().makePlanet()
    
    def outterRandomBody(self):
        return MediumTerrestrial().makePlanet() 
    
    def beltRandomBody(self):
        return MediumTerrestrial().makePlanet()

    def makeRandomRareBody(self):
        return BarrenFactory().makePlanet()
    
    def getOrbitalTable(self, SolarCore): 
        
        return [1,1.5,3.3,5.2,9.5,19.5,30, 50, 100]